#ifndef EMATH_H
#define EMATH_H

#include "stdafx.h"
#include "instruction.h"
#include "retour.h"
#include "fonction.h"

enum OpMath { OP_RIEN, OP_PLUS, OP_MOINS, OP_MOINS_UNAIRE, OP_DIVISION, OP_MULTIPLICATION, OP_EXPOSANT };
enum PrioMath { PRIO_ADDSOUS = 1, PRIO_MULDIV, PRIO_MOINS_UNAIRE, PRIO_EXPOSANT, PRIO_PAREN };

struct Operateur
{
	int type;
	int oper;
	int priorite;
};

class Emath; //forward declare

struct Symbole {
	int type;
	string *nom;
	Emath *arrayIndex;
};

union Terme
{
	int type;
	Constante con;
	Operateur op;
	Symbole syn;
};

class Emath : public Instruction
{
public:
	Emath();
	virtual ~Emath();
	void construire(list<Terme> src);
	list<Terme> convertir(list<token> src);
	Retour evaluer(map<string, Var_T> *loc, map<string, Var_T> *glob);
	Retour Emath::recupererVariable(map<string, Var_T> *contexte, map<string, Var_T> *loc, map<string, Var_T> *glob);

	Emath* droite;
	Emath* gauche;

	bool dejaCalculer;
	long double valeur;
	int operateur;
	
	bool estVariable;
	string nomVariable;

	bool estTableau;
	Emath* tableauIndex;
};

bool validerEmath(list<token> src);

#endif